
package com.jf.cloud.supplier.task;

import cn.hutool.core.collection.CollUtil;
import com.jf.cloud.supplier.constant.SupplierWalletZoneConstant;
import com.jf.cloud.supplier.service.SupplierDetailService;
import com.jf.cloud.supplier.service.SupplierWalletLogService;
import com.jf.cloud.supplier.service.SupplierWalletZoneService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 供应商定时任务
 *
 * @author zz
 * @Date 2021/7/9 13:35
 */
@Component
public class SupplierTask {

    @Autowired
    private SupplierDetailService supplierDetailService;
    @Autowired
    private SupplierWalletZoneService supplierWalletZoneService;
    @Autowired
    private SupplierWalletLogService supplierWalletLogService;

    /**
     * 根据签约时间改变供应商状态
     */
    @XxlJob("changeSupplierStatus")
    public void changeSupplierStatus() {
        Date now = new Date();
        // 根据签约时间修改店铺状态
        supplierDetailService.changeSupplierStatusByContractTime(now);
    }

    /**
     * 根据需要把供应商分成10片
     */
    @XxlJob("zoneSupplierWalletToTenIfNecessary")
    public void zoneSupplierWalletToTenIfNecessary() {

        List<Long> supplierIds = supplierWalletLogService.listNeedZoneSupplierIds(0);

        if (CollUtil.isEmpty(supplierIds)) {
            return;
        }

        // 进行钱包分片
        for (Long supplierId : supplierIds) {
            supplierWalletZoneService.doZone(0,supplierId);
        }

        // 移除缓存
        supplierWalletZoneService.removeZoneCache(supplierIds);
    }
}
